using System.Collections.Generic;
using UnityEngine;

public class StarsManager : MonoBehaviour
{
	private Dictionary<int, Star> stars = new Dictionary<int, Star>();

	private bool starsHidden;

	private float translationOffsetX = -4f;

	private float animationShowTime = 0.6f;

	private float animationHideTime = 0.6f;

	private float currentProgress;

	private void Awake()
	{
		stars.Add(1, base.transform.FindDeepChild("UI_Star_1").GetComponent<Star>());
		stars.Add(2, base.transform.FindDeepChild("UI_Star_2").GetComponent<Star>());
		stars.Add(3, base.transform.FindDeepChild("UI_Star_3").GetComponent<Star>());
	}

	public void SetProgress(float value)
	{
		if (value <= 0f)
		{
			value = 0f;
		}
		if (value >= 3f)
		{
			value = 3f;
		}
		currentProgress = value;
		float num = value;
		float num2 = Mathf.Min(1f, Mathf.Max(0f, num));
		num -= num2;
		float num3 = Mathf.Min(1f, Mathf.Max(0f, num));
		num -= num3;
		float progress = Mathf.Min(1f, Mathf.Max(0f, num));
		stars[1].SetProgress(num2);
		stars[2].SetProgress(num3);
		stars[3].SetProgress(progress);
	}

	public void ShowStars()
	{
		if (starsHidden)
		{
			starsHidden = false;
			iTween.MoveBy(base.gameObject, Vector3.right * translationOffsetX, animationShowTime);
		}
	}

	public void HideStars(bool hideImmediately)
	{
		if (!starsHidden)
		{
			starsHidden = true;
			if (hideImmediately)
			{
				base.transform.Translate(Vector3.left * translationOffsetX);
			}
			else
			{
				iTween.MoveBy(base.gameObject, Vector3.left * translationOffsetX, animationHideTime);
			}
		}
	}

	public int GetStars()
	{
		if (Mathf.Approximately(currentProgress, 1f))
		{
			return 1;
		}
		if (Mathf.Approximately(currentProgress, 2f))
		{
			return 2;
		}
		if (Mathf.Approximately(currentProgress, 3f))
		{
			return 3;
		}
		return Mathf.FloorToInt(currentProgress);
	}
}
